package com.bwie.doctorclient.service.impl;

import com.bwie.common.security.utils.SecurityUtils;
import com.bwie.doctorclient.domain.po.SymptomPO;
import com.bwie.doctorclient.domain.vo.CommonlyDrugVO;
import com.bwie.doctorclient.domain.vo.DepartmentVO;
import com.bwie.doctorclient.domain.vo.DrugVO;
import com.bwie.doctorclient.mapper.DrugMapper;
import com.bwie.doctorclient.service.DrugService;
import com.bwie.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugServiceImpl implements DrugService {
    @Autowired
    private DrugMapper drugMapper;

    /**
     * 获取常用药品列表
     * @return
     */
    @Override
    public List<CommonlyDrugVO> getCommonlyDrugList() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return drugMapper.getCommonlyDrugList(loginUser.getUserid());
    }

    /**
     * 删除常用药品
     * @param id
     * @return
     */
    @Override
    public void deleteCommonlyDrug(Long id) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        drugMapper.deleteCommonlyDrug(id,loginUser.getUserid());
    }

    /**
     * 新增常用药品
     * @param drugId
     * @return
     */
    @Override
    public void addCommonlyDrug(Long drugId) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        drugMapper.addCommonlyDrug(drugId,loginUser.getUserid());
    }

    /**
     * 获得所有科室及科室下的症状
     * @return
     */
    @Override
    public List<DepartmentVO> getDepartmentSymptomList() {
        //获取所有科室
        List<DepartmentVO> departmentVOList = drugMapper.getDepartmentList();

        //获取各个科室下的症状
        for (DepartmentVO departmentVO : departmentVOList) {
            List<SymptomPO> symptomPOS = drugMapper.getSymptomList(departmentVO.getId());
            departmentVO.setSymptomPOS(symptomPOS);
        }
        return departmentVOList;
    }

    /**
     * 根据科室症状id获取药品信息
     * @param ids
     * @return
     */
    @Override
    public List<CommonlyDrugVO> getDrugByDepartmentSymptomId(Long[] ids) {
        return drugMapper.getDrugByDepartmentSymptomId(ids[0],ids[1]);
    }

    /**
     * 获取药品详情
     * @param id
     * @return
     */
    @Override
    public DrugVO getDrugDetail(Long id) {
        return drugMapper.getDrugDetail(id);
    }
}
